﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Weazel.Willows.PreliminaryModel
{
	public class Register	
		: TypedItem
	{
		public Register(
			Model model, 
			XmlElement xmlElement, 
			ref IdentifierMap identifierMap
		)		
			: base(model)
		{
			read(xmlElement, ref identifierMap);
		}

		#region Read from XML
		private void read(XmlElement description, ref IdentifierMap identiferMap)
		{
			System.Diagnostics.Trace.Assert(description.Name == "Register");
			System.Diagnostics.Trace.Assert(description.HasAttribute("name"));
			System.Diagnostics.Trace.Assert(description.HasAttribute("type"));

			// get the name
			this.Name = description.Attributes["name"].Value;

			identiferMap.Add(this.Name, this);

			ReadType(description);
		}
		#endregion

		public void ExpandTo(Weazel.Willows.Model.Module module)
		{
			Weazel.Willows.Model.Register register =
				new Weazel.Willows.Model.Register(
					module,
					Model.TypeRegistry,
					Type,
					Name
				);

			module.Registers.Add(Name, register);
		}
	}
}
